import { Button, Space, message } from 'antd';
import { EditOutlined } from '@ant-design/icons';
import { wareaddService, wareditService } from '../services/ManageServices';
import { connect } from 'umi';

const UpdateContractBottom: React.FC = (curRes: any) => {
  const wareaddCallback = (res) => {
    if (res?.msgFlag) {
      message.success(res?.msg);
    } else {
      message.error(res?.msg);
    }
  };

  const { wareaddRun } = wareaddService(wareaddCallback);

  const wareditCallback = (res) => {
    if (res?.msgFlag) {
      message.success(res?.msg);
    } else {
      message.error(res?.msg);
    }
  };

  const { wareeditRun } = wareditService(wareditCallback);
  const param = curRes.getData();
  return (
    <>
      <div className="tabsBodyBottomBtn">
        <Space>
          <Button
            icon={<EditOutlined />}
            type={'primary'}
            onClick={() => {
              const param = curRes.getData();
              if (param?.pageType == 'add') {
                const obj: any = { ...param.data };
                wareaddRun(obj);
              } else if (param?.pageType == 'Edit') {
                const obj: any = { ...param.data };
                wareeditRun(obj);
              }
            }}
          >
            {param?.pageType == 'add' ? '保存' : '编辑'}
          </Button>
        </Space>
      </div>
    </>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin,
}))(UpdateContractBottom);
